package com.flying.function.blog;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import reactor.core.publisher.Flux;

import java.util.function.Function;

@SpringBootApplication
public class MyFunctionBootApp {

    @Bean
    public Function<Flux<Message<String>>, Flux<Message<String>>> uppercase() {
        return flux -> flux.map(value -> {
            return MessageBuilder.withPayload(value.getPayload().toUpperCase()).build();
        });
    }

    @Bean
    public Function<Flux<String>, Flux<String>> lowercase() {
        return flux -> flux.map(String::toLowerCase);
    }

    public static void main(String[] args) {
        SpringApplication.run(MyFunctionBootApp.class,
                "--spring.cloud.function.definition=uppercase;lowercase");
    }
}